<?php
class sis_pinjaman_anggota_detail_model extends MY_Model {
	var $model = 'sis_pinjaman_anggota_detail';
	
	function GetJSON()
	{
		$ls_sql	= "	SELECT	A.ID_PINJAMAN, A.PERIODE, TO_CHAR(A.TGL_JATUH_TEMPO,'DD/MM/YYYY') TGL_JATUH_TEMPO, A.JML_TAGIHAN, A.JML_BUNGA, A.TOTAL_TAGIHAN, 
							A.ST_LUNAS, A.TGL_LUNAS
					FROM	SIS_PINJAMAN_ANGGOTA_DETAIL A 
					WHERE	A.ID_PINJAMAN = '".post('id_pinjaman')."'
					ORDER BY A.PERIODE";
					
		return json_encode( $this->paging($ls_sql) );
	}
	
	function GetDetail($param=array())
	{
		
		$ls_sql	= "	SELECT	A.*
					FROM	SIS_PINJAMAN_ANGGOTA_DETAIL A
					ORDER BY ID_PINJAMAN";;
		$result = $this->db->query($ls_sql);
		if($result->num_rows() > 0){
			return $result->result_array();
		}else{
			return NULL;
		}
	}
	
	function Add($arr_data){
		$this->db->insert('SIS_PINJAMAN_ANGGOTA_DETAIL', $arr_data);
	}
	
	function Update($arr_data, $arr_rule){
		$this->db->update('SIS_PINJAMAN_ANGGOTA_DETAIL', $arr_data, $arr_rule);
	}
	
	function GetSingle($as_idpinjaman, $an_periode){
		$result = $this->db->get_where('SIS_PINJAMAN_ANGGOTA_DETAIL', array('ID_PINJAMAN' => $as_idpinjaman, 'PERIODE' => $an_periode));
		if($result->num_rows() == 1){
			return $result->row_array();
		}else{
			return NULL;
		}
	}
	
	function GetSingleView($as_idpinjaman, $an_periode)
	{
		$result = $this->db->get_where('SIS_PINJAMAN_ANGGOTA_DETAIL', array('ID_PINJAMAN' => $as_idpinjaman, 'PERIODE' => $an_periode));
		if($result->num_rows() == 1){
			return $result->row_array();
		}else{
			return NULL;
		}
	}

	function DeleteSingle($arr_rule)
	{
		try {
			if(	intval($this->get_data("SELECT COUNT(1) FROM SIS_ANGGOTA WHERE ID_PINJAMAN = '".$arr_rule['ID_PINJAMAN']."'"))>0)
			{
				return $this->error_delete.' [id: '.$arr_rule['ID_PINJAMAN']."]<br />";
			}else{
				$this->db->delete('SIS_PINJAMAN_ANGGOTA_DETAIL', array('ID_PINJAMAN' => $arr_rule['ID_PINJAMAN']));
				return '';
			}
		} catch(Exception $e) {
			return $e->getMessage();
		}
	}
}
?>